<template>
	<view class="content">
		<view class="bag" style="background-image: url(https://socialmall.yuntaiqikeji.com/uploads/20230606/66a7d772902d8181b04a09e61e3f690e.png);">
			<view class="header">
				<view class="denglu">输入手机号</view>
				<input type="number" placeholder="请输入注册手机号" class="zh" v-model="mobile">
				<view class="header_a flexbetween">
					<input type="number" placeholder="请输入手机验证码" class="mm" v-model="captcha">
					<view class="huoqu" @click="sendcode">{{codetext}}</view>
				</view>
				<view class="header_a flexbetween">
					<input :type="passwordType" placeholder="请输入新的密码" class="mm" v-model="newpassword">
					<view class="huoqu" @click="changeclick(1)">
						<image src="/static/image/home/eye.png" mode="" class="img" v-show="!quan"></image>
						<image src="/static/image/home/eyes.png" mode="" class="img" v-show="quan"></image>
					</view>
				</view>
				<view class="header_a flexbetween">
					<input :type="confirmPasswordType" placeholder="请再次输入新的密码" class="mm" v-model="confirmNewpassword">
					<view class="huoqu" @click="changeclick(2)">
						<image src="/static/image/home/eye.png" mode="" class="img" v-show="!quanConfirm"></image>
						<image src="/static/image/home/eyes.png" mode="" class="img" v-show="quanConfirm"></image>
					</view>
				</view>
				<view class="dl" @click="submit">完成</view>
			</view>
		</view>

	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				quan: false,
				quanConfirm: false,
				captcha: '',
				mobile: '',
				newpassword: "",
				confirmNewpassword: "",
				codetext: "获取验证码",
				passwordType: "password",
				confirmPasswordType: "password"
			}
		},
		onLoad() {

		},
		methods: {
			// 发送验证码
			sendcode() {
				let _this = this
				let mobile = _this.mobile;
				if (!mobile.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码");
					return false;
				}
				httpRequest.request('/api/sms/send', 'GET', {
					mobile: mobile,
					event: "resetpwd"
				}).then(resp => {
					if (resp.code == 1) {
						var i = 60;
						var timer = setInterval(function() {
							_this.codetext = i + "秒";
							if (i < 1) {
								clearInterval(timer);
								_this.codetext = "获取验证码";
							} else {
								i--;
							}
						}, 1000)

					} else if (resp.code == 0) {
						httpRequest.toast(resp.msg);
					} else {
						httpRequest.toast('网络开小差啦');
					}
				})
			},
			changeclick(type) { //是否显示密码
				if (type == 1) {
					this.quan = this.quan ? false : true
					this.passwordType = this.passwordType == "password" ? "text" : "password"
				} else {
					this.quanConfirm = this.quanConfirm ? false : true
					this.confirmPasswordType = this.confirmPasswordType == "password" ? "text" : "password"
				}
			},
			submit() {
				let _this = this
				if (this.mobile == '') {
					httpRequest.toast('请输入手机号！');
					return false;
				}
				if (!this.mobile.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码！");
					return false;
				}
				if (this.captcha == "") {
					httpRequest.toast('请输入验证码！');
					return false;
				}
				if (this.confirmNewpassword != this.newpassword) {
					httpRequest.toast('两次输入的密码不一致！');
					return false;
				}
				httpRequest.request('/api/user/resetpwd', 'GET', {
					mobile: _this.mobile,
					captcha: _this.captcha,
					newpassword: _this.newpassword,
				}).then(res => {
					if (res.code == 1) {
						httpRequest.toast(res.msg);
						setTimeout(() => {
							uni.navigateBack(1)
						}, 500)
					} else if (res.code == 0) {
						httpRequest.toast(res.msg);
					} else {
						httpRequest.toast('网络开小差啦');
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.huoqu {
		font-size: 30rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #D48B39;
		margin-right: 14rpx;
		min-width: 100rpx;
		text-align: right;
	}

	.orange {
		color: rgba(212, 139, 57, 1);
	}

	.bag {
		width: 100%;
		height: 100vh;
		background-size: 100% 100%;
	}

	.img {
		width: 28rpx;
		height: 20.36rpx;
	}

	.header_a {
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.10);
	}

	.content {
		background-color: #ffffff;
		min-height: 80vh;
	}

	.header {
		padding: 0rpx 30rpx;
	}

	.denglu {
		padding-top: 208rpx;
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	input:input-placeholder {
		color: #999999;
	}

	.zh {
		margin-top: 86rpx;
		padding-bottom: 28rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.10);
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.mm {
		flex: 1;
		margin-top: 44rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.10);
		padding-bottom: 45rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.yue {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-top: 71rpx;
		margin-left: 10rpx;
		margin-right: 8rpx;
	}


	.dl {
		margin-left: 10rpx;
		margin-right: 8rpx;
		margin-top: 146rpx;
		width: 672rpx;
		height: 82rpx;
		background-color: rgba(212, 139, 57, 1);
		font-size: 32rpx;
		border-radius: 41rpx 41rpx 41rpx 41rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 82rpx;
		text-align: center;
	}
</style>